const lo = require("../../../util/login.js")
const pa = require("../../../util/usesr_db.js")
Page({
  data: {
    userdata: null,
    userType: false,
  },
  // 获取用户手机号
  getUserNumber_user(res) {
    lo.getUserNumber_l(res)
    
  },
  // 获取用户信息
  getUserInfo(e) {
    console.log(e)
    let s_k = wx.getStorageSync("session_key")
    let s = s_k.openid
    this.setData({
      userdata: e.detail.userInfo,
      userType: true
    })
    console.log(this.data.userdata)                                                                                                               
    let data = e.detail.userInfo
    wx.setStorageSync("userdata", e.detail.userInfo)

    console.log(wx.getStorageSync("whereOpenid"))

    if (wx.getStorageSync("whereOpenid") == "" || wx.getStorageSync("whereOpenid") == undefined) {
      pa.addOpenidData(null,data)
      pa.whereOpenid()
    } else {
      pa.updateOpenidData(wx.getStorageSync("db_openid")[0]._id, data)
    }
    this.setData({
      userInfoDb: wx.getStorageSync("db_openid")
    })

  },

  // 判断当前数据中是否存在用户的session_key
  judgeUserData() {
    console.log(wx.getStorageSync("session_key"))
    lo.getUserInfoSession_l()
  },
  onLoad() {
    console.log(wx.getStorageSync("userdata"))
    // 判断当前小程序中是否已经成功存储用户信息
    if (wx.getStorageSync("userdata") == "" || wx.getStorageSync("userdata") == undefined || wx.getStorageSync("userdata") == null) {
      this.setData({
        userType: false
      })
    } else {
      this.setData({
        userdata: wx.getStorageSync("userdata"),
        userType: true
      })
    }
    this.judgeUserData()
    pa.whereOpenid()

  }
})